using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace DocLibApp
{
    public partial class FormSearchDoc : FormBase
    {
        private string SearchSQL = "";

        public FormSearchDoc()
        {
            InitializeComponent();
            SetupGUI();
        }

        private void SetupGUI()
        {
            util.SetupCombo(cboCategory, FormMain.DocLibStaticValueList, "DOC_CATEGORY");
            util.SetupCombo(cboDocType, FormMain.DocLibStaticValueList, "DOC_TYPE");
            util.SetupCombo(cboOwner, FormMain.DocLibStaticValueList, "DOC_OWNER");
            util.SetupCombo(cboImportance, FormMain.DocLibStaticValueList, "DOC_IMPORTANCE");
            util.SetupCombo(cboDocLocation, FormMain.DocLibStaticValueList, "DOC_LOCATION");
        }

        private void btnClearCriteria_Click(object sender, EventArgs e)
        {
            foreach (Control ctl in groupBox_Criteria.Controls)
            {
                if (ctl is System.Windows.Forms.ComboBox)
                    (ctl as System.Windows.Forms.ComboBox).SelectedIndex = 0;
                else if (ctl is System.Windows.Forms.TextBox)
                    (ctl as System.Windows.Forms.TextBox).Text = "";
            }

            lsv_Result.Items.Clear();
        }

        private void btnSearch_Click(object sender, EventArgs e)
        {
            System.Collections.Hashtable ht = SaveDataToHashFromControls(groupBox_Criteria.Controls);

            System.Collections.ArrayList alist = doc_operation.SearchDocument(ht);

            lsv_Result.ShowData(alist, "DOC_ID", def.tb_doc);
        }

        private void btnShowSQL_Click(object sender, EventArgs e)
        {
            ShowMessage(SearchSQL);
        }

        private void lsv_Result_DoubleClick(object sender, EventArgs e)
        {
            if (lsv_Result.SelectedItems.Count > 0)
            {
                ListViewItem item = lsv_Result.SelectedItems[0];
                string doc_id = item.Tag.ToString().Trim();
                OpenDocument(doc_id);
            }
        }

        private void saveSearchToolStripMenuItem_Click(object sender, EventArgs e)
        {

        }
    }
}